<?php

/**
 * 地区接口
 */
class Action
{
    private $token = '';
    private $user_id = 0;
    private $user_info = array();
    private $api_stat_id = 0;

    public function __construct() {
        $this->token = an_request('token');

        if ($this->token) {
            $user_info = user_helper::get_user_info_by_token($this->token);
            if ($user_info && $user_info['status'] == 1) {
                $this->user_id = $user_info['id'];
                $this->user_info = $user_info;
            }
        }
    }

    /**
     * get_provinces
     */
    public function get_provinces()
    {
        $check_params = array();
        $this->api_stat_id = api_helper::check_sign($check_params, 1);

        $province_list = _widget('area')->get_province_list();
        api_helper::return_data(0, 'success', $province_list, $this->api_stat_id);
    }

    /**
     * get_citys
     */
    public function get_citys_by_province()
    {
        $province_code = an_request('area_code');

        $check_params = array(
            'province_code' => $province_code,
        );
        $this->api_stat_id = api_helper::check_sign($check_params, 1);

        $city_list = _widget('area')->get_city_list($province_code);
        api_helper::return_data(0, 'success', $city_list, $this->api_stat_id);
    }

    /**
     * get_countys
     */
    public function get_countys_by_city()
    {
        $city_code = an_request('area_code');

        $check_params = array(
            'city_code' => $city_code,
        );
        $this->api_stat_id = api_helper::check_sign($check_params, 1);

        $county_list = _widget('area')->get_county_list($city_code);
        api_helper::return_data(0, 'success', $county_list, $this->api_stat_id);
    }
}